package inner;

interface Runner{
	public abstract void run();
}

class MyMath{
	public int add(int a ,int b) {
		return a + b;
	}
	public int sub(int a ,int b) {
		return a - b;
	}
}
public class AnonInnerClassDemo {
	public static void main(String[] args) {
		// 接口、抽象类，普通类
		MyMath m1 = new MyMath() {
			@Override
			public int sub(int a, int b) {
				return a*2-b;
			}
			@Override
			public int add(int a, int b) {
				return a*2+b;
			}
		};
		System.out.println(m1.sub(1, 2));
		System.out.println(m1.add(1, 2));
		
		
		// 是一个实现了Runner接口的没有名字的内部类（匿名内部类属于方法内部类的）
		Runner r = new Runner() {
			@Override
			public void run() {
				System.out.println("腿跑");
			}
		};
		r.run();
		
		Runner r2 = new Runner() {
			@Override
			public void run() {
				System.out.println("轮子跑");
			}
		};
		r2.run();
	}
}
